

//时间戳处理
Handlebars.registerHelper('format', function (date,options) {

    var str = new Date(date).toLocaleString();
    var i = str.indexOf(' ');
    var str1 = str.substr(i + 1,2);
    var str2 = str.substr(i + 3,2);

    if (isNaN(str2)) {
        if (str1 == '上午') {
            str = str.replace(str.substr(i + 1,3),'0' + str.substr(i + 3,1));
        }else {
            str = str.replace(str.substr(i + 1,3),Number(str.substr(i + 3,1)) + 12);
        }
    }else{
        if (str1 == '上午') {
            str = str.replace(str.substr(i + 1,2),'');
        }else {
            if(Number(str2) == 12){
                str = str.replace(str.substr(i + 1,4),'00');
            }else {
                str = str.replace(str.substr(i + 1,4),Number(str.substr(i + 3,2)) + 12);
            }
        }
    }
    return str;
});
//
//
Handlebars.registerHelper('if_eq', function(v1, v2, opts) {
    if(v1 == v2)
        return opts.fn(this);
    else
        return opts.inverse(this);
});
//
$('.record').click(function(){
    $('.record').removeClass('item-active');
    $(this).addClass('item-active');
    $('.main-item').hide();
    var index = $(this).index();
    $('.main-content').children().eq(index).show();
});
$('.list-tab a').click(function(){
    $('.list-tab a').removeClass('active-tab');
    $(this).addClass('active-tab');
});
recharge();
project();
$('.withdraw').click(function(){
    withdraw();
});
$('.recharge').click(function(){
    recharge();
});
function withdraw(){
    $('.recharge-thead').css('display','none');
    $('.withdraw-thead').css('display','table-header-group');
    $.ajax({
        url:"/assets/script/account-withdraw.hbs",
        type:"get",
        async:false,
        success:function(data){
            tpl2=data;
        }
    });
    var template2 = Handlebars.compile(tpl2);
    $.ajax({
        url:'/account-center.json',
        type: 'get',
        dataType:"json",
        success: function (data) {
            var html = template2(data);
            $('.history').empty();
            $('.history').append(html);
        },
        error:function (msg) {
            console.log(msg)
        }
    });
}
function recharge(){
    $('.recharge-thead').css('display','table-header-group');
    $('.withdraw-thead').css('display','none');
    $.ajax({
        url:"/assets/script/account-recharge.hbs",
        type:"get",
        async:false,
        success:function(data){
            tpl=data;
        }
    });
    var template = Handlebars.compile(tpl);
    $.ajax({
        url:'/account-center.json',
        type: 'get',
        dataType:"json",
        success: function (data) {
            var html = template(data);
            $('.history').empty();
            $('.history').append(html);
        },
        error:function (msg) {
            console.log(msg)
        }
    });
}

function project(){
    $.ajax({
        url:"/assets/script/account-project.hbs",
        type:"get",
        async:false,
        success:function(data){
            tpl1=data;
        }
    });
    var template1 = Handlebars.compile(tpl1);
    $.ajax({
        url:'/account-center.json',
        type: 'get',
        dataType:"json",
        success: function (data) {
            var html = template1(data);
            $('.investeds').empty();
            $('.investeds').append(html);
        },
        error:function (msg) {
            console.log(msg)
        }
    });
}
$.ajax({
    url:'/account-center.json',
    type: 'get',
    dataType:"json",
    success: function (data) {
        if(!data.totalValuation){
            $('.valuation').html('- -');
        }else{
            $('.valuation').html(data.totalValuation + ' BTC');
        }

    },
    error:function (msg) {
        console.log(msg)
    }
});

//
// $(".invested-item").hover(function(){
//     $(".cover").show();
// },function(){
//     $(".cover").hide();
// })
// $('.invested-item').mouseenter(function(){
//     $('.cover').css('display','block');
// });
// $('.invested-item').mouseleave(function(){
//     $('.cover').css('display','none');
// });